package com.example.blog.controller;

import com.example.blog.pojo.request.AddBlogRequest;
import com.example.blog.pojo.request.UpdateBlogRequest;
import com.example.blog.pojo.response.BlogInfoResponse;
import com.example.blog.pojo.response.Result;
import com.example.blog.service.BlogService;
import jakarta.annotation.Resource;
import jakarta.validation.constraints.NotNull;
import lombok.extern.slf4j.Slf4j;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/blog")
public class BlogController {
    @Resource(name = "blogServiceImpl")
    private BlogService blogService;
    @GetMapping("/getList")
    public List<BlogInfoResponse> getList(){
        return blogService.getList();
    }

    @GetMapping("getBlogCount")
    public Integer getBlogCount(){
        return blogService.getBlogCount();
    }

    @GetMapping("/getBlogDetail")
    public BlogInfoResponse getBlogDetail(@NotNull(message = "blogId 不能为null") Integer blogId){
        log.info("查询博客详情,blogId:{}",blogId);
        return blogService.getBlogDetail(blogId);
    }

    @PostMapping("/add")
    public Result addBlog(@Validated @RequestBody AddBlogRequest addBlogRequest){
        log.info("发布博客，request:{}",addBlogRequest);
        return Result.ok(blogService.addBlog(addBlogRequest)) ;
    }

    @PostMapping("/update")
    public Boolean updateBlog(@Validated @RequestBody UpdateBlogRequest updateBlogRequest){
        log.info("修改博客，request:{}",updateBlogRequest);
        return blogService.updateBlog(updateBlogRequest);
    }

    @PostMapping("/delete")
    public Boolean deleteBlog(@NotNull Integer blogId){
        log.info("删除博客，blogId:{}",blogId);
        return blogService.deleteBlog(blogId);
    }
}






























